package stack_queue.leetcode.Leetcode;


import java.util.LinkedList;
import java.util.Queue;

/**
 * @author shkstart
 * @create 2022-10-12-16:21
 */
public class MyStackByOneQueue {

    private Queue<Integer> queue;

    public MyStackByOneQueue() {
        queue = new LinkedList<>();
    }

    public void push(int x) {
//        1.获取元素个数
        int size = queue.size();
//        2.先入队
        queue.add(x);
//        3.将前N个元素出队同时入队
        for (int i = 0; i < size; i++) {
            queue.add(queue.poll());
        }
    }

    public int pop() {
 return queue.poll();
    }

    public int top() {
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }
}
